package com.txm.exception;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by tangxinmao on 2017/3/13.
 * 捕获异常
 */
@RestControllerAdvice
public class ExceptionHandle {
    private static Log logger = LogFactory.getLog(ExceptionHandle.class);
    @ExceptionHandler(value = RuntimeException.class)
    @ResponseBody
    public Map exception(RuntimeException e) {
         Map map=new HashMap();
        if(e instanceof MyException){
            //构造异常返回结果
        } else {
            logger.error("elasticsearch", e);
        }
        logger.info(e);//打印异常
        return map ;
    }
}
